package com.bilibili.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bilibili.entity.Danmaku;
import com.bilibili.service.SelectDanmuService;
import com.bilibili.service.impl.SelectDanmuServiceImpl;

@WebServlet("/insertDanmu.do")
public class InsertDanmuServlet extends HttpServlet {
	
	private SelectDanmuService sds=new SelectDanmuServiceImpl();
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String videoId=request.getParameter("videoId");
		String userId=request.getParameter("userId");
		String content=request.getParameter("content");
		System.out.println(content);
		int videoid=0;
		int userid=0;
		if(videoId != null) {
			videoid=Integer.parseInt(videoId);
		}
		if(userId != null&& !userId.equals("")) {
			userid=Integer.parseInt(userId);
		}
		Danmaku dm=new Danmaku();
		dm.setVideoId(videoid);
		dm.setUserId(userid);
		dm.setContent(content);
		sds.insertDanmu(dm);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(req, resp);
	}

}
